//
//  XJNavigationController.m
//  AppFrame
//
//  Created by GXJ on 2017/2/24.
//  Copyright © 2017年 GXJ. All rights reserved.
//

#import "XJNavigationController.h"

@interface XJNavigationController ()

@end

@implementation XJNavigationController

+ (void)initialize
{
    [self setupNavigationBarStyle];
    [self setupNavigationItemStyle];
}

+ (void)setupNavigationBarStyle
{
    UINavigationBar *navigationBar = [UINavigationBar appearance];
    [navigationBar setBackgroundColor:APPColor];//
    [navigationBar setBarTintColor:APPColor];
    navigationBar.translucent = NO;
    
    NSMutableDictionary *attributeDict = [NSMutableDictionary dictionary];
    attributeDict[NSForegroundColorAttributeName] = [UIColor whiteColor];
    attributeDict[NSFontAttributeName] = [UIFont fontWithName:HEITIMEDIUM size:18];
    [navigationBar setTitleTextAttributes:attributeDict];
}

+ (void)setupNavigationItemStyle
{
    UIBarButtonItem *navigationItem = [UIBarButtonItem appearance];
    
    NSMutableDictionary *attributeDict = [NSMutableDictionary dictionary];
    attributeDict[NSForegroundColorAttributeName] = [UIColor whiteColor];
    attributeDict[NSFontAttributeName] = [UIFont fontWithName:HEITILIGHT size:16];
    [navigationItem setTitleTextAttributes:attributeDict forState:UIControlStateNormal];
    
    NSMutableDictionary *disableAttributeDict = [NSMutableDictionary dictionary];
    disableAttributeDict[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    disableAttributeDict[NSFontAttributeName] = [UIFont fontWithName:HEITILIGHT size:16];
    [navigationItem setTitleTextAttributes:disableAttributeDict forState:UIControlStateDisabled];
    
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 20)];
        [backButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
        [backButton setTitle:@"返回" forState:0];
        backButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [backButton setImageEdgeInsets:UIEdgeInsetsMake(0, -20, 0, 0)];
        //backButton.frame.size = CGSizeMake(30, 30);
        [backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    }
    [super pushViewController:viewController animated:animated];
}

- (void)backAction:(UIButton *)sender
{
   
    [self popViewControllerAnimated:YES];
}


@end
